// Created from GenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Reflection;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.Generated.AbstractMessage;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using TX = System.String;
using FT = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class BAR_P05 : AbstractMessage
    {
		/// Constructor
		public BAR_P05() : base()
        {
			if (MSH != null) {
                MSH.MessageType = new MSG() { MessageCode = "BAR", TriggerEvent = "P05" };
			}
        }

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("EVN",2)]
  	    [HL7Field(HL7Version.v23, 2, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v231, 2, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v24, 2, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v25, 3, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v251, 3, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v26, 4, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v27, 4, HL7Repeat.False, HL7Required.True,"EVN")]
	    public EVN EVN {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PID",3)]
  	    [HL7Field(HL7Version.v23, 3, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v231, 3, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v24, 3, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v25, 4, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v251, 4, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v26, 5, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v27, 5, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PD1",6)]
  	    [HL7Field(HL7Version.v23, 6, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v231, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v24, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v25, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v251, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v26, 6, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v27, 6, HL7Repeat.False, HL7Required.False,"PD1")]
	    public PD1 PD1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("VISIT",8)]
  	    [HL7Field(HL7Version.v23, 8, HL7Repeat.True, HL7Required.True,"VISIT_BAR_P05")]
  	    [HL7Field(HL7Version.v231, 7, HL7Repeat.True, HL7Required.True,"VISIT_BAR_P05")]
  	    [HL7Field(HL7Version.v24, 12, HL7Repeat.True, HL7Required.True,"VISIT_BAR_P05")]
  	    [HL7Field(HL7Version.v25, 7, HL7Repeat.True, HL7Required.True,"VISIT_BAR_P05")]
  	    [HL7Field(HL7Version.v251, 7, HL7Repeat.True, HL7Required.True,"VISIT_BAR_P05")]
  	    [HL7Field(HL7Version.v26, 8, HL7Repeat.True, HL7Required.True,"VISIT_BAR_P05")]
  	    [HL7Field(HL7Version.v27, 8, HL7Repeat.True, HL7Required.True,"VISIT_BAR_P05")]
	    public VISIT_BAR_P05[] VISIT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("GT1",51)]
  	    [HL7Field(HL7Version.v23, 51, HL7Repeat.True, HL7Required.False,"GT1")]
  	    [HL7Field(HL7Version.v231, 49, HL7Repeat.True, HL7Required.False,"GT1")]
  	    [HL7Field(HL7Version.v24, 59, HL7Repeat.True, HL7Required.False,"GT1")]
	    public GT1[] GT1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("NK1",56)]
  	    [HL7Field(HL7Version.v23, 56, HL7Repeat.True, HL7Required.False,"NK1")]
  	    [HL7Field(HL7Version.v231, 54, HL7Repeat.True, HL7Required.False,"NK1")]
  	    [HL7Field(HL7Version.v24, 64, HL7Repeat.True, HL7Required.False,"NK1")]
	    public NK1[] NK1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("INSURANCE",59)]
  	    [HL7Field(HL7Version.v23, 59, HL7Repeat.False, HL7Required.False,"INSURANCE_BAR_P05")]
  	    [HL7Field(HL7Version.v231, 57, HL7Repeat.False, HL7Required.False,"INSURANCE_BAR_P05")]
  	    [HL7Field(HL7Version.v24, 67, HL7Repeat.False, HL7Required.False,"INSURANCE_BAR_P05")]
	    public INSURANCE_BAR_P05 INSURANCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ACC",71)]
  	    [HL7Field(HL7Version.v23, 71, HL7Repeat.False, HL7Required.False,"ACC")]
  	    [HL7Field(HL7Version.v231, 71, HL7Repeat.False, HL7Required.False,"ACC")]
  	    [HL7Field(HL7Version.v24, 86, HL7Repeat.False, HL7Required.False,"ACC")]
	    public ACC ACC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("UB1",74)]
  	    [HL7Field(HL7Version.v23, 74, HL7Repeat.False, HL7Required.False,"UB1")]
  	    [HL7Field(HL7Version.v231, 74, HL7Repeat.False, HL7Required.False,"UB1")]
  	    [HL7Field(HL7Version.v24, 89, HL7Repeat.False, HL7Required.False,"UB1")]
	    public UB1 UB1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("UB2",77)]
  	    [HL7Field(HL7Version.v23, 77, HL7Repeat.False, HL7Required.False,"UB2")]
  	    [HL7Field(HL7Version.v231, 77, HL7Repeat.False, HL7Required.False,"UB2")]
  	    [HL7Field(HL7Version.v24, 92, HL7Repeat.False, HL7Required.False,"UB2")]
	    public UB2 UB2 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ROL",9)]
  	    [HL7Field(HL7Version.v24, 9, HL7Repeat.True, HL7Required.False,"ROL")]
  	    [HL7Field(HL7Version.v25, 6, HL7Repeat.True, HL7Required.False,"ROL")]
  	    [HL7Field(HL7Version.v251, 6, HL7Repeat.True, HL7Required.False,"ROL")]
  	    [HL7Field(HL7Version.v26, 7, HL7Repeat.True, HL7Required.False,"ROL")]
  	    [HL7Field(HL7Version.v27, 7, HL7Repeat.True, HL7Required.False,"ROL")]
	    public ROL[] ROL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ABS",95)]
  	    [HL7Field(HL7Version.v24, 95, HL7Repeat.False, HL7Required.False,"ABS")]
	    public ABS ABS {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("BLC",99)]
  	    [HL7Field(HL7Version.v24, 99, HL7Repeat.True, HL7Required.False,"BLC")]
	    public BLC[] BLC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RMI",103)]
  	    [HL7Field(HL7Version.v24, 103, HL7Repeat.False, HL7Required.False,"RMI")]
	    public RMI RMI {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("SFT",2)]
  	    [HL7Field(HL7Version.v25, 2, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v251, 2, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v26, 2, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v27, 2, HL7Repeat.True, HL7Required.False,"SFT")]
	    public SFT[] SFT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("UAC",3)]
  	    [HL7Field(HL7Version.v26, 3, HL7Repeat.False, HL7Required.False,"UAC")]
  	    [HL7Field(HL7Version.v27, 3, HL7Repeat.False, HL7Required.False,"UAC")]
	    public UAC UAC {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override Stack<string> ConsumeTextSegments(Stack<string> availableData, HL7ParserOptions options) {

				if (HL7Version.v23 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 VISIT = ProcessGroupArray<VISIT_BAR_P05>(availableData, options, "VISIT");
		 GT1 = PopSegmentParseAndCheckRequiredArray<GT1>(availableData, options, "GT1");
		 NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
		 INSURANCE = ProcessGroup<INSURANCE_BAR_P05>(availableData, options, "INSURANCE");
		 ACC = PopSegmentParseAndCheckRequired<ACC>(availableData, options, "ACC");
		 UB1 = PopSegmentParseAndCheckRequired<UB1>(availableData, options, "UB1");
		 UB2 = PopSegmentParseAndCheckRequired<UB2>(availableData, options, "UB2");
		}
		if (HL7Version.v231 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 VISIT = ProcessGroupArray<VISIT_BAR_P05>(availableData, options, "VISIT");
		 GT1 = PopSegmentParseAndCheckRequiredArray<GT1>(availableData, options, "GT1");
		 NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
		 INSURANCE = ProcessGroup<INSURANCE_BAR_P05>(availableData, options, "INSURANCE");
		 ACC = PopSegmentParseAndCheckRequired<ACC>(availableData, options, "ACC");
		 UB1 = PopSegmentParseAndCheckRequired<UB1>(availableData, options, "UB1");
		 UB2 = PopSegmentParseAndCheckRequired<UB2>(availableData, options, "UB2");
		}
		if (HL7Version.v24 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 VISIT = ProcessGroupArray<VISIT_BAR_P05>(availableData, options, "VISIT");
		 GT1 = PopSegmentParseAndCheckRequiredArray<GT1>(availableData, options, "GT1");
		 NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
		 INSURANCE = ProcessGroup<INSURANCE_BAR_P05>(availableData, options, "INSURANCE");
		 ACC = PopSegmentParseAndCheckRequired<ACC>(availableData, options, "ACC");
		 UB1 = PopSegmentParseAndCheckRequired<UB1>(availableData, options, "UB1");
		 UB2 = PopSegmentParseAndCheckRequired<UB2>(availableData, options, "UB2");
		 ROL = PopSegmentParseAndCheckRequiredArray<ROL>(availableData, options, "ROL");
		 ABS = PopSegmentParseAndCheckRequired<ABS>(availableData, options, "ABS");
		 BLC = PopSegmentParseAndCheckRequiredArray<BLC>(availableData, options, "BLC");
		 RMI = PopSegmentParseAndCheckRequired<RMI>(availableData, options, "RMI");
		}
		if (HL7Version.v25 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 VISIT = ProcessGroupArray<VISIT_BAR_P05>(availableData, options, "VISIT");
		 ROL = PopSegmentParseAndCheckRequiredArray<ROL>(availableData, options, "ROL");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		}
		if (HL7Version.v251 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 VISIT = ProcessGroupArray<VISIT_BAR_P05>(availableData, options, "VISIT");
		 ROL = PopSegmentParseAndCheckRequiredArray<ROL>(availableData, options, "ROL");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		}
		if (HL7Version.v26 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 VISIT = ProcessGroupArray<VISIT_BAR_P05>(availableData, options, "VISIT");
		 ROL = PopSegmentParseAndCheckRequiredArray<ROL>(availableData, options, "ROL");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		}
		if (HL7Version.v27 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 VISIT = ProcessGroupArray<VISIT_BAR_P05>(availableData, options, "VISIT");
		 ROL = PopSegmentParseAndCheckRequiredArray<ROL>(availableData, options, "ROL");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		}
			if (availableData != null && availableData.Count > 0) {
				ConsumeZSegmentsFromText(availableData, options);
			}
            return availableData;
        
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "BAR_P05";
			}
        }

        static BAR_P05() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(BAR_P05));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
			if (MSH != null) {
				segmentData.Add(MSH.GetER7(options));
			}
			if (EVN != null) {
				segmentData.Add(EVN.GetER7(options));
			}
			if (PID != null) {
				segmentData.Add(PID.GetER7(options));
			}
			if (PD1 != null) {
				segmentData.Add(PD1.GetER7(options));
			}
			if (VISIT != null && VISIT.Length > 0) {
				for (int i = 0; i < VISIT.Length; i++) {
					segmentData.Add(VISIT[i].GetER7(options));
				}
			}
			if (GT1 != null && GT1.Length > 0) {
				for (int i = 0; i < GT1.Length; i++) {
					segmentData.Add(GT1[i].GetER7(options));
				}
			}
			if (NK1 != null && NK1.Length > 0) {
				for (int i = 0; i < NK1.Length; i++) {
					segmentData.Add(NK1[i].GetER7(options));
				}
			}
			if (INSURANCE != null) {
				segmentData.Add(INSURANCE.GetER7(options));
			}
			if (ACC != null) {
				segmentData.Add(ACC.GetER7(options));
			}
			if (UB1 != null) {
				segmentData.Add(UB1.GetER7(options));
			}
			if (UB2 != null) {
				segmentData.Add(UB2.GetER7(options));
			}
			if (ROL != null && ROL.Length > 0) {
				for (int i = 0; i < ROL.Length; i++) {
					segmentData.Add(ROL[i].GetER7(options));
				}
			}
			if (ABS != null) {
				segmentData.Add(ABS.GetER7(options));
			}
			if (BLC != null && BLC.Length > 0) {
				for (int i = 0; i < BLC.Length; i++) {
					segmentData.Add(BLC[i].GetER7(options));
				}
			}
			if (RMI != null) {
				segmentData.Add(RMI.GetER7(options));
			}
			if (SFT != null && SFT.Length > 0) {
				for (int i = 0; i < SFT.Length; i++) {
					segmentData.Add(SFT[i].GetER7(options));
				}
			}
			if (UAC != null) {
				segmentData.Add(UAC.GetER7(options));
			}
           segmentData.AddRange(GetZSegmentsER7(options));
		   return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }


    }
}

